﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MMS.BLL;
using MMS.Model;

namespace MarketMS
{
    public partial class FormMoney : Form
    {
        public FormMoney()
        {
            InitializeComponent();
        }
        private OrderManager om = new OrderManager();
        private void btnSearch_Click(object sender, EventArgs e)
        {
            DateTime start = dtpStart.Value;
            DateTime end = dtpEnd.Value;
            if (start > end)
            {
                MessageBox.Show("开始时间不能大于结束时间");
                return;
            }
            List<OrderGoods> list = om.GetTop10BuyCountGoods(start,end);
            dgvGoods.DataSource = new BindingList<OrderGoods>(list);
        }

        private void FormMoney_Load(object sender, EventArgs e)
        {
            dgvGoods.AutoGenerateColumns = false;
            dgvOrderDetail.AutoGenerateColumns = false;
        }

        private void dgvGoods_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }

        private void dgvGoods_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DateTime start = dtpStart.Value;
            DateTime end = dtpEnd.Value;
            //获取到选中的行(事件参数可以获取当前点击的是第几行，然后直接从所有的行中获取点击行)
            DataGridViewRow dr = dgvGoods.Rows[e.RowIndex];
            //获取商品编号(当前行.所有的单元格[下标].Value)
            string goodsCode = dr.Cells[0].Value.ToString();
            dgvOrderDetail.DataSource = new BindingList<GoodsOrderDetail>(om.GetGoodsOrderDetail(goodsCode, start, end));
        }
    }
}
